home *** CD-ROM | disk | FTP | other *** search
/ Keyframe Magazine 6 / KeyFrame Magazine, Issue 6 - May-June 1998 WIN-MAC (David Warner)(1998).iso / mac / ParentBone / DanzParentBone.LS next >
Text File  |  1998-01-14  |  7KB  |  301 lines

  1. //dan R's Parent anything motion plugin
  2. // replacement for parent bone
  3. // does alot more
  4. // 
  5. // parent, unparent
  6. // temperal offset (use with IK to make "drag behind" bones like tails and long ears.)
  7.  
  8.  
  9.             //example of info
  10.                 //info("Object ",refobject.name," has ",refobject.pointcount," points.");
  11.  
  12.  
  13.     var refobjectname;
  14.     var refob;
  15.     var refobb;
  16.     var refobc;
  17.     var timeoffset;
  18.     var modifyposition;
  19.     var modifyrotation;
  20.     var parentonlyrotation;
  21.     var relativeposition;
  22.     var newparrt[3];
  23.     var newparrt3;
  24.     var newparrt4;
  25.     var newpos[3];
  26.     var newpos2;
  27.     var newpos4;
  28.     var c0,c1,c2,c3,c4,c5,c6;
  29.     var cur;
  30.     var curb;
  31.     var thisobject;
  32.     var thisobjectb;
  33.     var thistime;
  34.     var thisframe;
  35.     var startparent;
  36.     var stopparent;
  37.     var startparenttime;
  38.     var stopparenttime;
  39.     var refobname2;
  40.     var mythisobject;
  41.  
  42.  
  43. create {
  44.  
  45.     refobjectname="";
  46.     timeoffset = 0;
  47.     modifyposition = true;
  48.     modifyrotation = false;
  49.     parentonlyrotation = false;
  50.     relativeposition = false;
  51.     newparrt[]=0.0;
  52.     //newparrt3 = < 0.0 , 0.0 , 0.0 >;
  53.     //newparrt4 = < 0.0 , 0.0 , 0.0 >;
  54.     newpos[3]=0.0;
  55.     newpos2 = <0.0 , 0.0 , 0.0>;
  56.     //newpos4 = <0.0 , 0.0 , 0.0>;
  57.  
  58.     startparent = 0;
  59.     stopparent = 9999;
  60.     startparenttime = 0.001;
  61.     stopparenttime = 0.001;
  62.     refobname2 = "";
  63.     mythisobject = 0;
  64.     
  65.  
  66.     setdesc("danz parent anything 1.3");  // set panel button text
  67.  
  68.  
  69.     }
  70.  
  71.  
  72. options  {
  73.           //display options requester
  74.  
  75.                 if(!reqbegin("parent bone - the revenge:"))
  76.                     return;     // no Panel Services plug-in
  77.  
  78.         addtext ("danz parent bone plugin for lscript 1.3","");
  79.         addtext ("copyright 1997 dan ritchie","all rights reserved","");
  80.         addtext ("Shareware fee $20.00 US. Send to: Parent Bone","");
  81.         addtext ("PO BOX 621 Oldsmar FL. 34677-0621   USA","");
  82.   
  83.              c0 = addcontrol(refobjectname,"current");
  84.  
  85.                 c1 = additems("select parent from list");  //adds a dropdown control to pick an object
  86.                                     //from a list of all objects
  87.             c2 = addcheckbox(modifyposition,"inheirit position");
  88.  
  89.                 c3 = addcheckbox(relativeposition,"allow motion relative to parent");
  90.  
  91.             c5 = addcheckbox(parentonlyrotation,"use rotation from parent");
  92.  
  93.             //c4 = addcheckbox(modifyrotation,"full rotation (don't work right)");
  94.  
  95.             c6 = addcontrol(timeoffset,"temporal offset in frames (negative Ok)");
  96.  
  97.             c7 = addcontrol(startparent,"start parenting at frame");
  98.  
  99.             c8 = addcontrol(stopparent,"stop parenting at frame");
  100.  
  101.  
  102.  
  103.             reqpost();
  104.                      // if(( refobject = getvalue(c1)) == nil)
  105.                    //    return;
  106.  
  107.             refobject = getvalue(c1);
  108.             refobname2 = getvalue(c0);
  109.             modifyposition = getvalue(c2);
  110.             relativeposition = getvalue(c3);
  111.             modifyrotation = 0;                 //getvalue(c4);
  112.             parentonlyrotation = getvalue(c5);
  113.             timeoffset = getvalue(c6);
  114.             startparent    =  getvalue(c7);
  115.             stopparent =  getvalue(c8);
  116.                     reqend();
  117.  
  118.         if (refobject != nil)
  119.         {
  120.             refobjectname = refobject.name;
  121.         }
  122.         else
  123.         {
  124.         refobjectname = refobname2; 
  125.         }
  126.     return;
  127.  
  128.     }
  129.  
  130.  
  131.  
  132. process: thisobject,thisframe,thistime
  133.     {
  134.  
  135.     
  136.             //this is here so i can remember it...
  137.             //get(attribute,time);
  138.             //set(attribute,value);
  139.                   //this function allows you to set the specified 'attribute'
  140.                   //(POSITION, ROTATION, SCALING) to the provided vector 'value'
  141.  
  142.               //get time
  143.             timeminusoffset = thistime - (timeoffset/30);  //time offset;
  144.             startparenttime = (startparent / 30);
  145.             stopparenttime = (stopparent / 30);
  146.  
  147.               // start and stop parenting...
  148.             if (timeminusoffset < startparenttime) {timeminusoffset = startparenttime;}
  149.             if (timeminusoffset > stopparenttime) {timeminusoffset = stopparenttime;}
  150.  
  151.               //get position of parent
  152.             refob = getfirstitem(refobjectname);
  153.             newpos2 = refob.param(WPOSITION,timeminusoffset);
  154.             //newpos2 = refob.getWorldPosition(timeminusoffset);
  155.                 newpos[1] = newpos2.x;
  156.                 newpos[2] = newpos2.y;
  157.                 newpos[3] = newpos2.z;
  158.     
  159.  
  160.               //get rotation of parent
  161.             if (parentonlyrotation == true) 
  162.             {
  163.                 refobb = getfirstitem(refobjectname);
  164.                 newparrt3 = refobb.param(ROTATION,timeminusoffset);
  165.                 curb = thisobject.get(ROTATION,thistime);
  166.                 newparrt[1] = newparrt3.x + curb.x;  //actually h, p, b
  167.                 newparrt[2] = newparrt3.y + curb.y;
  168.                 newparrt[3] = newparrt3.z + curb.z;
  169.             }
  170.  
  171.               //get rotation of all parent objects
  172.             if (modifyrotation == true)
  173.             {
  174.                 curb = thisobject.get(ROTATION,thistime);
  175.                 newparrt[1] = curb.x;  //actually h, p, b
  176.                 newparrt[2] = curb.y;
  177.                 newparrt[3] = curb.z;
  178.  
  179.                  //loop until read all parents
  180.             //so what i need to do is...
  181.             //go until thisobject = refobc
  182.                 refoc=nil;
  183.                 mythisobject=nil;
  184.                 refobc = getfirstitem(refobjectname);
  185.                 mythisobject = thisobject.objID;
  186.                 while (refobc.name != mythisobject.name )
  187.                     {
  188.                     if ( refobc != nil )
  189.                         {
  190.                 info (" obj 1: ", refobc.name , " obj 2: " , mythisobject.name);
  191.                         newparrt4 = refobc.param(ROTATION,timeminusoffset);
  192.                         newparrt[1] = newparrt[1] + newparrt4.x;
  193.                         newparrt[2] = newparrt[2] + newparrt4.y;
  194.                         newparrt[3] = newparrt[3] + newparrt4.z;
  195.                         }
  196.                     refobc = refobc.next();
  197.                     }
  198.  
  199.             }
  200.  
  201.         
  202.  
  203.         //only modify position if user wants it...
  204.         if (modifyposition == true)
  205.         {
  206.               //caculate position relative to parent
  207.             if (relativeposition == 1)
  208.                 {
  209.                 cur = thisobject.get(POSITION,thistime);
  210.                 newpos[1] = newpos2.x + cur.x;
  211.                 newpos[2] = newpos2.y + cur.y;
  212.                 newpos[3] = newpos2.z + cur.z;
  213.                 }
  214.               //set position
  215.             thisobject.set(POSITION,<newpos[1],newpos[2],newpos[3]>);    
  216.         }
  217.  
  218.           //modify rotation if user wants it...
  219.         if ((parentonlyrotation == true) || (modifyrotation == true))
  220.         {
  221.               //set Rotation from parent
  222.             thisobject.set(ROTATION,<newparrt[1],newparrt[2],newparrt[3]>);    
  223.         }
  224.  
  225. //end process:
  226.     }
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234. save: what, io
  235. {
  236. if(what == SCENEMODE)   // processing an ASCII scene file
  237.     {
  238.     io.writeln("refobjectname::",refobjectname);
  239.     io.writeln("timeoffset ",timeoffset);
  240.     io.writeln("modifyposition ",modifyposition);
  241.     io.writeln("modifyrotation ",modifyrotation);
  242.     io.writeln("parentonlyrotation ",parentonlyrotation);
  243.     io.writeln("relativeposition ",relativeposition);
  244.     io.writeln("startparent ",startparent);
  245.     io.writeln("stopparent ",stopparent);
  246.     }
  247. }
  248.  
  249. load: what, io
  250. {
  251. var line = "";
  252. var items[2];
  253.  
  254. if(what == SCENEMODE)
  255.     {
  256.         line = io.read();
  257.         items=parse("::",line);
  258.         refobjectname = items[2];
  259.  
  260.         line = nil;
  261.         line = io.read();
  262.         items = parse(" ",line);
  263.         timeoffset  = integer(items[2]);
  264.  
  265.         line = nil;
  266.         line = io.read();
  267.         items = parse(" ",line);
  268.         modifyposition  = integer(items[2]);
  269.  
  270.         line = nil;
  271.         line = io.read();
  272.         items = parse(" ",line);
  273.         modifyrotation  = integer(items[2]);
  274.  
  275.         line = nil;
  276.         line = io.read();
  277.         items = parse(" ",line);
  278.         parentonlyrotation  = integer(items[2]);
  279.  
  280.         line = nil;
  281.         line = io.read();
  282.         items = parse(" ",line);
  283.         relativeposition  = integer(items[2]);
  284.  
  285.         line = nil;
  286.         line = io.read();
  287.         items = parse(" ",line);
  288.          startparent  = integer(items[2]);
  289.  
  290.         line = nil;
  291.         line = io.read();
  292.         items = parse(" ",line);
  293.         stopparent  = integer(items[2]);
  294.         
  295.     }
  296. }
  297.  
  298.  
  299.  
  300.  
  301.